package com.you.atlas.web.home.module.screen;

import javax.servlet.http.HttpServletRequest;

import com.alibaba.citrus.service.uribroker.uri.URIBroker;
import com.alibaba.citrus.turbine.Navigator;
import com.alibaba.citrus.turbine.TurbineRunData;
import com.alibaba.citrus.turbine.dataresolver.Param;
import com.google.gdata.client.douban.DoubanService;
import com.you.atlas.web.home.helper.DoubanClientHelper;

public class DoubanSign {

    public void execute(@Param(name = "done") String done, HttpServletRequest request, TurbineRunData rundata,
                        Navigator navigator) {

        DoubanService myService = DoubanClientHelper.getDoubanService();
        URIBroker uriBroker = navigator.redirectTo("homeModule").withTarget("doubanRegiste").uri();
        if (done != null) {
            uriBroker.addQueryData("done", done);
        }
        String url = myService.getAuthorizationUrl(uriBroker.render());
        String secret = myService.getRequestTokenSecret();
        rundata.getRequest().getSession().setAttribute("douban_secret", secret);
        navigator.redirectToLocation(url);
    }
}
